//
//  LGPatientNumberController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/23.
//  输入患者登记号

#import "LGPatientNumberController.h"
//添加患者
#import "LGPatientNewlyController.h"
//新建、完善咨询记录
#import "LGConsultRecordAddController.h"
//最新病情概览
#import "LGDiseaseOverviewController.h"
#import "LGConsultRecordLineView.h"
#import "LGConsultPatientRepetionView.h"
@interface LGPatientNumberController ()
/**   */
@property (nonatomic , strong)LGConsultRecordLineView *numberView;
/**   */
@property (nonatomic , strong)UIButton *nextButton;
/**   */
@property (nonatomic , copy)NSString *patientid;
/**   */
@property (nonatomic , copy)NSString *diseaseCode;
/**   */
@property (nonatomic , copy)NSString *levelid;

//0038134267
@end

@implementation LGPatientNumberController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationView.title = @"输入患者登记号";
    [self.view addSubview:self.numberView];
    [self.view addSubview:self.nextButton];
}

-(void)textFieldEditingChanged:(UITextField *)textField{
    NSString *content = (textField.text.length>10)?[textField.text substringToIndex:10]:textField.text;
    self.numberView.contentTF.text = content;
    if(content.length == 10){
        self.nextButton.selected = NO;
    }else{
        self.nextButton.selected = YES;
    }
}

//下一步
-(void)nextButtonAction{
    if(self.nextButton.selected == NO){
        [RequestUtil withPOST:@"/doctor/patient.Followup/followupByHospitalbano" parameters:@{@"hospital_bano":self.numberView.contentTF.text,@"followup_date":self.followDate} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if(code == 200){
                self.patientid = LGNSString(returnData[@"patient_id"]);
                self.diseaseCode = LGNSString(returnData[@"diseaseCode"]);
                self.levelid = LGNSString(returnData[@"level_id"]);
                NSString *type = LGNSString(returnData[@"jumpType"]);
                if([type isEqualToString:@"0"]){
                    //去建档
                    LGPatientNewlyController *controller = [[LGPatientNewlyController alloc]init];
                    controller.patientNum = self.numberView.contentTF.text;
                    controller.followDate = self.followDate;
                    [self.navigationController pushViewController:controller animated:YES];
                    
                }else if ([type isEqualToString:@"1"]){
                    //新增咨询记录
                    LGConsultRecordAddController *controller = [[LGConsultRecordAddController alloc]init];
                    controller.patientid = LGNSString(returnData[@"patient_id"]);
                    controller.diseaseCode = LGNSString(returnData[@"diseaseCode"]);
                    controller.levelid = LGNSString(returnData[@"level_id"]);
                    controller.isAdd = YES;
                    [self.navigationController pushViewController:controller animated:YES];
                    
                }else if ([type isEqualToString:@"2"] || [type isEqualToString:@"3"]){
                    //完善咨询记录 、 最新病情概览
                    LGConsultPatientRepetionView *alertView = [[LGConsultPatientRepetionView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
                    [[UIApplication sharedApplication].keyWindow addSubview:alertView];
                    __weak typeof(self) weakSelf = self;
                    alertView.checkConsultRecord = ^{
                        //完善咨询记录
                        LGConsultRecordAddController *controller = [[LGConsultRecordAddController alloc]init];
                        controller.patientid = weakSelf.patientid;
                        controller.diseaseCode = weakSelf.diseaseCode;
                        controller.levelid = weakSelf.levelid;
                        controller.isAdd = NO;
                        [weakSelf.navigationController pushViewController:controller animated:YES];
                    };
                }
            }
        } error:^(NSError *error) {
            
        }];
    }
}


-(LGConsultRecordLineView *)numberView{
    if(!_numberView){
        _numberView = [[LGConsultRecordLineView alloc] initWithFrame:CGRectMake(viewPix(16), topBarHeight+viewPix(12), Screen_W-viewPix(32), viewPix(54))];
        _numberView.contentTF.keyboardType = UIKeyboardTypeNumberPad;
        _numberView.title = @"登记号";
        _numberView.required = YES;
        [_numberView.contentTF addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    }
    return _numberView;
}

-(UIButton *)nextButton{
    if(!_nextButton){
        _nextButton = [UIButton buttonWithTitle:@"下一步" topMargin:Screen_H-viewPix(80)-bottomSafeBarHeight/4.0];
        _nextButton.selected = YES;
        [_nextButton addTarget:self action:@selector(nextButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextButton;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
